using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Microsoft.ApplicationBlocks.Data;
using Customs.Components.KDT.GC.Info;
namespace Customs.Components.KDT.GC
{
    public class HangChuyenTiep:HangChuyenTiepInfo
    {
        public void Load(HangChuyenTiepInfo HCTInfo)
        {
            this._SoTiepNhan = HCTInfo.SoTiepNhan;
            this._MaHQTN= HCTInfo.MaHQTN;
            this._NamTiepNhan = HCTInfo.NamTiepNhan;
            this._MaChungTu = HCTInfo.MaChungTu;
            this._SoChungTu = HCTInfo.SoChungTu;
            this._NamChungTu = HCTInfo.NamChungTu;
            this._NgayChungTu = HCTInfo.NgayChungTu;
            this._MaHS = HCTInfo.MaHS;
            this._MaHang = HCTInfo.MaHang;
            this._TenHang = HCTInfo.TenHang;
            this._ID_NuocXX = HCTInfo.ID_NuocXX;
            this._ID_DVT = HCTInfo.ID_DVT;
            this._SoLuong = HCTInfo.SoLuong;
            this._DonGia = HCTInfo.DonGia;
            this._TriGia = HCTInfo.TriGia;
            this._MaHQ = HCTInfo.MaHQ;
            this.STTHang = HCTInfo.STTHang;
        }
        //--------------------------------------------------------------------
        public static void Delete(SqlTransaction transaction, long soTiepNhan, string maHaiQuan,int namTiepNhan)
        {
            string query = string.Format("DELETE FROM tblDHangCTGC WHERE SO_TNDKDT = {0} AND MA_HQTN = '{1}' AND NAM_TN = {2} ", soTiepNhan, maHaiQuan.PadRight(6), namTiepNhan);
            SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, query);
        }
        
        //--------------------------------------------------------------------
        public void InsertTransaction(SqlTransaction transaction, HangChuyenTiepInfoCollection collection)
        {
            HangChuyenTiep hct = new HangChuyenTiep();
            foreach (HangChuyenTiepInfo itemInfo in collection)
            {
                hct.Load(itemInfo);
                hct.InsertTransaction(transaction);
            }
        }
        //--------------------------------------------------------------------
        public void InsertTransaction(SqlTransaction transaction)
        {
            StringBuilder query = new StringBuilder();
            query.Append("INSERT INTO tblDHangCTGC ( ");
            query.Append("So_TNDKDT, ");
            query.Append("Ma_HQTN, ");
            query.Append("Nam_TN, ");
            query.Append("So_CT, ");
            query.Append("Ma_CT, ");
            query.Append("Nam_CT, ");
            query.Append("Ngay_CT, ");
            query.Append("Ma_HQ, ");
            query.Append("P_Code, ");
            query.Append("HS_Code, ");
            query.Append("TenHang,");
            query.Append("SoLuong,");
            query.Append("Ma_DVT,");
            query.Append("DonGia,");
            query.Append("TriGia,");
            query.Append("NuocXX,");
            query.Append("STTHang)");

            query.Append("VALUES ( ");

            query.Append("@So_TNDKDT, ");
            query.Append("@Ma_HQTN, ");
            query.Append("@Nam_TN, ");
            query.Append("@So_CT, ");
            query.Append("@Ma_CT, ");
            query.Append("@Nam_CT, ");
            query.Append("@Ngay_CT, ");
            query.Append("@Ma_HQ, ");
            query.Append("@P_Code, ");
            query.Append("@HS_Code, ");
            query.Append("@TenHang,");
            query.Append("@SoLuong,");
            query.Append("@Ma_DVT,");
            query.Append("@DonGia,");
            query.Append("@TriGia,");
            query.Append("@NuocXX,");
            query.Append("@STTHang)");

            SqlParameter[] parameters = new SqlParameter[17];

            parameters[0] = new SqlParameter("@So_TNDKDT", SqlDbType.BigInt);
            parameters[0].Value = this._SoTiepNhan;

            parameters[1] = new SqlParameter("@Ma_HQTN", SqlDbType.Char, 6);
            parameters[1].Value = this._MaHQTN;

            parameters[2] = new SqlParameter("@Nam_TN", SqlDbType.SmallInt);
            parameters[2].Value = this._NamTiepNhan;

            parameters[3] = new SqlParameter("@So_CT", SqlDbType.Int);
            parameters[3].Value = this._SoChungTu;

            parameters[4] = new SqlParameter("@Ma_CT", SqlDbType.VarChar, 7);
            parameters[4].Value = this._MaChungTu;

            parameters[5] = new SqlParameter("@Nam_CT", SqlDbType.Int);
            parameters[5].Value = this._NamChungTu;

            parameters[6] = new SqlParameter("@Ngay_CT", SqlDbType.DateTime);
            parameters[6].Value = this._NgayChungTu;

            parameters[7] = new SqlParameter("@Ma_HQ", SqlDbType.VarChar, 6);
            parameters[7].Value = this._MaHQ;

            parameters[8] = new SqlParameter("@P_Code", SqlDbType.VarChar, 30);
            parameters[8].Value = this._MaHang;

            parameters[9] = new SqlParameter("@HS_Code", SqlDbType.VarChar, 12);
            parameters[9].Value = this._MaHS;

            parameters[10] = new SqlParameter("@TenHang", SqlDbType.NVarChar,80);
            parameters[10].Value = this.TenHang;

            parameters[11] = new SqlParameter("@SoLuong", SqlDbType.Decimal);
            parameters[11].Value = this.SoLuong;

            parameters[12] = new SqlParameter("@Ma_DVT", SqlDbType.VarChar, 3);
            parameters[12].Value = this.ID_DVT;

            parameters[13] = new SqlParameter("@DonGia", SqlDbType.Money);
            parameters[13].Value = this.DonGia;

            parameters[14] = new SqlParameter("@TriGia", SqlDbType.Money);
            parameters[14].Value = this.TriGia;

            parameters[15] = new SqlParameter("@NuocXX", SqlDbType.VarChar, 3);
            parameters[15].Value = this._ID_NuocXX;

            parameters[16] = new SqlParameter("@STTHang", SqlDbType.Int);
            parameters[16].Value = this._SoThuTuHang;

            SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, query.ToString(), parameters);
        }	
    }
}
